package com.cdxy.model.dto.base.mybatis;

/**
 * @Author: tangy
 * @Date: 2020/2/26 2:09
 */

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.io.Serializable;

public class BaseRepository<M extends BaseMapper<T>, T> extends ServiceImpl<M, T> {
    protected static final String FOR_UPDATE = "for update";
    protected static final String LIMIT_1 = "limit 1";

    public BaseRepository() {
    }

    protected String limitN(Integer n) {
        if (n == null) {
            throw new IllegalArgumentException("n不能为空");
        } else {
            return "limit ".concat(n.toString());
        }
    }

    protected LambdaQueryWrapper<T> queryWrapper() {
        return (new QueryWrapper()).lambda();
    }

    protected LambdaUpdateWrapper<T> updateWrapper() {
        return (new UpdateWrapper()).lambda();
    }

    protected T getByPrimaryForUpdate(Serializable id) {
        return (T) ((BaseMapper)this.baseMapper).getByPrimaryForUpdate(id);
    }
}

